﻿Public Class QuanLyThuNhanh

    Dim mapt As String = ""

    Private Sub QuanLyThuNhanh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbNguoiThu.DataSource = ProcFunc.ExecuteFuncSQL("select * from [User]")
        cbNguoiThu.ValueMember = "MaUser"
        cbNguoiThu.DisplayMember = "TenUser"
        cbNguoiThu.SelectedIndex = -1
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If cbNguoiThu.Text <> "" And txtSoTienThu.Text <> "" Then
            'Tao ma phieu thu
            Dim str = "00"
            Dim day As String = str.Substring(0, 2 - dateNgayThu.Value.Day.ToString.Length) & dateNgayThu.Value.Day
            Dim month As String = str.Substring(0, 2 - dateNgayThu.Value.Month.ToString.Length) & dateNgayThu.Value.Month
            Dim year As String = dateNgayThu.Value.Year.ToString.Substring(dateNgayThu.Value.Year.ToString.Length - 2, 2)
            mapt = ProcFunc.ExecuteFuncSSQL("select max(MaPhieuThu) from PhieuThu where MaPhieuThu like N'PT" & day & month & year & "%'").ToString()
            If mapt = String.Empty Then
                mapt = "PT" + day & month & year & "0001"
            Else
                mapt = "PT" & (mapt.Substring(2, mapt.Length - 2) + 1)
            End If
            '//

            str = "insert into PhieuThu values ('" & mapt & "','" & cbNguoiThu.SelectedValue & "','NH1','TN5','" &
                String.Format("{0:yyyy-MM-dd}", dateNgayThu.Value) & "','" & txtSoTienThu.Value.ToString.Trim & "',N'')"
            ProcFunc.ExecuteProcSQL(str)

            MessageBox.Show("Dữ liệu đã được thêm")

        Else
            MessageBox.Show("Xin vui lòng điền đủ thông tin")
        End If
    End Sub
End Class